package com.itwxz.system.controller.pc;


import com.itwxz.common.annotation.Log;
import com.itwxz.common.core.controller.BaseController;
import com.itwxz.common.core.domain.AjaxResult;
import com.itwxz.common.core.page.TableDataInfo;
import com.itwxz.common.enums.BusinessType;
import com.itwxz.common.utils.poi.ExcelUtil;
import com.itwxz.system.domain.po.WxzCarousel;
import com.itwxz.system.service.IWxzCarouselService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.List;

/**
 * 轮播图Controller
 *
 * @author gastronome
 * @date 2025-04-29
 */
@Tag(name = "轮播图Controller")
@RestController
@RequestMapping("/wxz/carousel")
public class WxzCarouselController extends BaseController {
	@Autowired
	private IWxzCarouselService wxzCarouselService;

	/**
	 * 查询轮播图列表
	 */
	@Operation(summary = "查询轮播图列表")
	@PreAuthorize("@ss.hasPermi('wxz:carousel:list')")
	@GetMapping("/list")
	public TableDataInfo list(WxzCarousel wxzCarousel) {
		startPage();
		List<WxzCarousel> list = wxzCarouselService.selectWxzCarouselList(wxzCarousel);
		return getDataTable(list);
	}

	/**
	 * 导出轮播图列表
	 */
	@Operation(summary = "导出轮播图列表")
	@PreAuthorize("@ss.hasPermi('wxz:carousel:export')")
	@Log(title = "轮播图", businessType = BusinessType.EXPORT)
	@PostMapping("/export")
	public void export(HttpServletResponse response, WxzCarousel wxzCarousel) {
		List<WxzCarousel> list = wxzCarouselService.selectWxzCarouselList(wxzCarousel);
		ExcelUtil<WxzCarousel> util = new ExcelUtil<WxzCarousel>(WxzCarousel.class);
		util.exportExcel(response, list, "轮播图数据");
	}

	/**
	 * 获取轮播图详细信息
	 */
	@Operation(summary = "获取轮播图详细信息")
	@PreAuthorize("@ss.hasPermi('wxz:carousel:query')")
	@GetMapping(value = "/{id}")
	public AjaxResult getInfo(@PathVariable("id") Long id) {
		return success(wxzCarouselService.getById(id));
	}

	/**
	 * 新增轮播图
	 */
	@CacheEvict(value = "carousel", key = "'list'")
	@Operation(summary = "新增轮播图")
	@PreAuthorize("@ss.hasPermi('wxz:carousel:add')")
	@Log(title = "轮播图", businessType = BusinessType.INSERT)
	@PostMapping
	public AjaxResult add(@RequestBody WxzCarousel wxzCarousel) {
		return toAjax(wxzCarouselService.save(wxzCarousel));
	}

	/**
	 * 修改轮播图
	 */
	@CacheEvict(value = "carousel", key = "'list'")
	@Operation(summary = "修改轮播图")
	@PreAuthorize("@ss.hasPermi('wxz:carousel:edit')")
	@Log(title = "轮播图", businessType = BusinessType.UPDATE)
	@PutMapping
	public AjaxResult edit(@RequestBody WxzCarousel wxzCarousel) {
		return toAjax(wxzCarouselService.updateById(wxzCarousel));
	}

	/**
	 * 删除轮播图
	 */
	@CacheEvict(value = "carousel", key = "'list'")
	@Operation(summary = "删除轮播图")
	@PreAuthorize("@ss.hasPermi('wxz:carousel:remove')")
	@Log(title = "轮播图", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
	public AjaxResult remove(@PathVariable Long[] ids) {
		return toAjax(wxzCarouselService.removeByIds(Arrays.asList(ids)));
	}
}
